/************************************************
* 文件描述: 提交成功的处理
* 待完善:  变量未修改
* 待优化:  尚未读懂代码
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*************************************************/
#include "submitBase.h"
#include "smtpMailClient.h"
#include <QPainterPath>
#include <QLayout>

/* 适配组内SDK */
#include "windowmanage.hpp"

SubmitBase::SubmitBase(QWidget *parent) :
    QDialog(parent)
{
    initUI();
}
void SubmitBase::initUI()
{
    if (this->objectName().isEmpty())
        this->setObjectName(QString::fromUtf8("submit_success"));
    this->setAttribute(Qt::WA_ShowModal, true);
    this->setFixedSize(236,60);

    m_notifyText = new QLabel(this);
    m_notifyText->adjustSize();
    m_notifyText->setStyleSheet("font-size:14px;");
    m_notifyText->setObjectName(QString::fromUtf8("label"));
    m_notifyText->setGeometry(QRect(75, 19, 118, 22));

    m_picBtn = new QPushButton(this);
    m_picBtn->setObjectName(QString::fromUtf8("label_2"));
    m_picBtn->setGeometry(QRect(43, 18, 24, 24));
    m_picBtn->setFixedSize(QSize(24, 24));
    m_picBtn->setIconSize(QSize(24, 24));
    m_picBtn->setFlat(true);
    m_picBtn->setAttribute(Qt::WA_TransparentForMouseEvents);


    QHBoxLayout *hlt_menu=new QHBoxLayout;//窗体内部，水平布局
    hlt_menu->setMargin(0);
    hlt_menu->setSpacing(0);
    hlt_menu->addSpacing(43);
    hlt_menu->addWidget(m_picBtn, 1);
    hlt_menu->addSpacing(8);
    hlt_menu->addWidget(m_notifyText, 1);
    hlt_menu->addStretch(99);

    QVBoxLayout *vlt_menu=new QVBoxLayout;//窗体内部，水平布局
    vlt_menu->setMargin(0);
    vlt_menu->setSpacing(0);
    vlt_menu->addSpacing(18);
    vlt_menu->addLayout(hlt_menu, 1);
    vlt_menu->addStretch(99);

    m_body = new QWidget;//窗体
    m_body->setFixedSize(236,60);
    m_body->setObjectName("body");
    m_body->setLayout(vlt_menu);

    QHBoxLayout *hlt_suc=new QHBoxLayout;//窗体内部，水平布局
    hlt_suc->setMargin(0);
    hlt_suc->setSpacing(0);
    hlt_suc->addSpacing(0);
    hlt_suc->addWidget(m_body, 1);
    hlt_suc->addSpacing(0);
    QVBoxLayout *vlt_suc=new QVBoxLayout;//窗体内部，水平布局
    vlt_suc->setMargin(0);
    vlt_suc->setSpacing(0);
    vlt_suc->addSpacing(0);
    vlt_suc->addLayout(hlt_suc, 1);
    vlt_suc->addSpacing(0);

    this->setLayout(vlt_suc);

    /* 适配kysdk的窗管 */
    ::kabase::WindowManage::removeHeader(this);
}
SubmitBase::~SubmitBase()
{

}
void SubmitBase::show_faillinfo(int error_code)
{
    switch (error_code) {
    case int(SmtpErrType::SmtpConnectOverTime):
        m_notifyText->setText(tr("Server Connect Overtime!"));
        qWarning() << (tr("与邮箱服务器链接超时"));
        break;
    case int(SmtpErrType::SmtpFeedBackOverTime):
        m_notifyText->setText(tr("FeedBack Overtime!"));
        qWarning() << (tr("smtp返回信息超时"));
        break;
    case int(SmtpErrType::MailServerNotReady):
        m_notifyText->setText(tr("Server Unready!"));
        qWarning() << (tr("mail服务器未准备好"));
        break;
    case int(SmtpErrType::MailLoginFailed):
        m_notifyText->setText(tr("Login Failed!"));
        qWarning() << (tr("邮箱登录失败"));
        break;
    case int(SmtpErrType::SendMailConfigFeedBackOverTime):
        m_notifyText->setText(tr("Mail Set Failed!"));
        qWarning() << (tr("邮箱用户设置失败"));
        break;
    case int(SmtpErrType::SmtpMailSendFailed):
        m_notifyText->setText(tr("Mail Send Failed!"));
        qWarning() << (tr("邮件发送失败"));
        break;
    case int(SmtpErrType::SmtpMailQuitFailed):
        m_notifyText->setText(tr("Mail Quit Failed!"));
        qWarning() << (tr("邮件退出失败"));
        break;
    case int(SmtpErrType::SmtpLocalInfoUnready):
        m_notifyText->setText(tr("Local Info Unready!"));
        qWarning() << (tr("本机信息未获取完毕"));
        break;
    default:
        m_notifyText->setText(tr("Unknown Error!"));
        qWarning() << (tr("未知错误"));
        break;
    }
}

void SubmitBase::setLabelMovie()
{
    m_timer = new QTimer(this);
    m_timer->start(100);
    connect(m_timer,SIGNAL(timeout()),this,SLOT(gifPlay()));
}
void SubmitBase::gifPlay()
{
    QString picName = "";

    if (m_count > 8)
    {
        m_count = 1;
    }

    switch (m_count)
    {
        case 1:
            picName="ukui-loading-symbolic-0";
            break;
        case 2:
            picName="ukui-loading-symbolic-1";
            break;
        case 3:
            picName="ukui-loading-symbolic-2";
            break;
        case 4:
            picName="ukui-loading-symbolic-3";
            break;
        case 5:
            picName="ukui-loading-symbolic-4";
            break;
        case 6:
            picName="ukui-loading-symbolic-5";
            break;
        case 7:
            picName="ukui-loading-symbolic-6";
            break;
        case 8:
            picName="ukui-loading-symbolic-7";
            break;
        default:
            break;
    }
    ++m_count;
//    m_ui->pixIcon->setProperty("useIconHighlightEffect", 0x10);
    m_picBtn->setIcon(QIcon::fromTheme(picName));
}
void SubmitBase::setLabelPix(QString pixPath)
{
    m_picBtn->setStyleSheet(pixPath);
}

void SubmitBase::setLabelText(QString text)
{
    m_notifyText->setText(text);
}

void SubmitBase::changePageForTheme(const QString& str)
{
    setBackgroundRole(QPalette::Window);
}
